package com.aizhixin.test.question.controller;

import java.util.List;

import org.aspectj.apache.bcel.classfile.Module.Require;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.aizhixin.test.question.dao.addOrDeleteOrChangeQuestionDAO;
import com.aizhixin.test.question.dto.QuestionDTO;
import com.aizhixin.test.question.dto.addChangeDeleteQuestionDTO;
import com.aizhixin.test.question.dto.addorChangeOrDeleteoptionDTO;
import com.aizhixin.test.question.service.addorchangeordeleteQuestionService;

import org.springframework.http.MediaType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping(value="/v1/open/masterAddOrChangeQuestion")
@Api(tags="管理者的管理试题（添加或修改或删除试题）API")
@Slf4j
public class addorDeleteOrChangeQuestionController {
	@Autowired
	private addorchangeordeleteQuestionService addorchangeordeleteQuestionService;
	@PostMapping(value="/qusetion",produces=MediaType.APPLICATION_JSON_VALUE)
	@ApiOperation(httpMethod="POST",value="添加试题",notes="添加试题<br><br><b>@author xixi</b>")
	public addChangeDeleteQuestionDTO addQuestion(
			@ApiParam(value="添加试题所需要的条件",required=true)
			@RequestBody addChangeDeleteQuestionDTO dto){
		return addorchangeordeleteQuestionService.addQuestion(dto);
	}
	
	@GetMapping(value="/",produces=MediaType.APPLICATION_JSON_VALUE)
	@ApiOperation(httpMethod="GET",value="获取最后一个试题的题号+1（添加的时候获取了直接输入就可以了，已经加一了）")
	public Long getSeamId() {
		return addorchangeordeleteQuestionService.getsteamid();
	}
	
	@PostMapping(value="/qusetionOption",produces=MediaType.APPLICATION_JSON_VALUE)
	@ApiOperation(httpMethod="POST",value="添加试题选项",notes="添加试题选项<br><br><b>@author xixi</b>")
	public addorChangeOrDeleteoptionDTO addoption(
			@ApiParam(value="添加试题选项所需要的条件",required=true)
			@RequestBody addorChangeOrDeleteoptionDTO dto){
		return addorchangeordeleteQuestionService.addoption(dto);
	}
	
	
	@PutMapping(value = "/question1",produces=MediaType.APPLICATION_JSON_VALUE)
	@ApiOperation(httpMethod="PUT",value="修改试题",notes="修改试题<br><br><b>@author xixi</b>")
	public addChangeDeleteQuestionDTO putMethodName(
			@ApiParam(value="修改试题所需条件")
			@RequestBody addChangeDeleteQuestionDTO dto) {
	return addorchangeordeleteQuestionService.chandequestion(dto);
	}
	
	
	@PutMapping(value="/qusetionOption1",produces=MediaType.APPLICATION_JSON_VALUE)
	@ApiOperation(httpMethod="PUT",value="修改试题选项",notes="修改试题选项<br><br><b>@author xixi</b>")
	public addorChangeOrDeleteoptionDTO changeoption(
			@ApiParam(value = "修改试题选项所需要的条件", required = true)
			@RequestBody addorChangeOrDeleteoptionDTO dto) {
		return addorchangeordeleteQuestionService.changeoption(dto);
	}

	@DeleteMapping(value = "/{questionID}", produces = MediaType.APPLICATION_JSON_VALUE)
	@ApiOperation(httpMethod = "DELETE", value = "删除试题及选项", notes = "删除试题<br><br><b>@author xixi</b>")
	public boolean delete(@ApiParam(value = "题目ID") @PathVariable Long questionID) {
		return addorchangeordeleteQuestionService.deleteQuestionAndOption(questionID);
	}
}
